var treeSetting = {
 		view : {
 			fontCss: { fontSize: "14px" }
 		},
 		data : {
 			simpleData : {
 				enable : true,
 				idKey : "id",
 				pIdKey : "pId"
 			}
 		},
 		check: {
 			enable:false
 		},
 	    callback : {
 	        // 单击左侧事件
 	    	onClick: businessUnitzTreeOnClick
 	    }
 	 };


//节点点击事件
function businessUnitzTreeOnClick(event, treeId, treeNode) {
	$('#buName').val(treeNode.name);
    //$('#buGuid').val(treeNode.id);
    console.log(treeNode.name+"=="+treeNode.id);
    alert("aaa");
   // hideTree();  
};
//下拉框显示 隐藏
function showBusinessUnitTree(){
    if($('#ztree_div').css('display') == 'none'){
        $('#ztree_div').css('display','block'); 
    } else{
        $('#ztree_div').css('display','none'); 
    }
   // $("body").bind("mousedown", onBodyDownByActionType); 
}
function hideTree() {  
    $('#ztree_div').css('display','none');
    $("body").unbind("mousedown", onBodyDownByActionType); 
    return false;
} 
//区域外点击事件
function onBodyDownByActionType(event) {  
    if (event.target.id.indexOf('buNameTree') == -1){  
        if(event.target.id != 'selectDevType'){
            hideTree(); 
        } 
    }  
}
$(document).ready(function () {
	//获取所有级别项目数据
	//单位guid
	var companyId="b77cef1f-4eab-4e5a-9bf4-ef874fb9a694";
	$.ajax({
		url : ctx + "/common/dialog/debug/getBusinessUnitList",
		type : "post",
		dataType : "json",
		async : false,
		data:{
			buGuid:companyId
		},
		success : function(result) {
			if (result.success) {
				//初始组织树状图
			    $.fn.zTree.init($("#buNameTree"), treeSetting, result.businessUnitList);
			    // 弹出框的宽度等于文本框的宽度
			    var selecIptW = $('.org-select').css('width');
			    $(".selecTree").innerWidth(selecIptW)
			}
		},
		error : function() {
			console.info("getProjectAllList error");
		},
		complete : function() {
		}
	});
});
